﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bzure.Mvc;
using Bzure.Common.Core;

namespace System
{
    public static class ApplicationStartContextAppSetionExtensions
    {
        static Dictionary<string, AppSection> _sections = new Dictionary<string, AppSection>();
        public static void RegisterAppSection(this IApplicationStartContext StartContext, AppSection app)
        {
            _sections[app.SectionName] = app;
        }
        public static AppSection[] AppSections(this Public Public)
        {
            return _sections.Values.OrderBy(m => m.Index).ToArray();
        }
        public static AppSection CurrentAppSection(this Public Public)
        {
            string area = Public.GetAreaName();
            if (area.IsNullOrEmpty())
                return default(AppSection);
            return _sections.Values.Where(m => m.SectionName.Equals(area, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
        }
        public static AppSection AppSectionByUrl(this Public Public, string url)
        {
            string area = Public.GetAreaName(url);
            if (area.IsNullOrEmpty())
                return default(AppSection);
            return _sections.Values.Where(m => m.SectionName.Equals(area, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
        }
    }
}
